#include "wtrack.h"

WTrack::WTrack(QWidget *parent) :
    WTable(parent)
{
    tableView->setModel(&model);
    tableView->setColumnWidth(DtTrack::Play, 30);
    tableView->setColumnWidth(DtTrack::Add, 30);
    tableView->setColumnWidth(DtTrack::Number, 50);
    tableView->setColumnWidth(DtTrack::Name, 300);
    tableView->setColumnWidth(DtTrack::Artist, 150);
    tableView->setColumnWidth(DtTrack::Album, 150);
    tableView->setColumnWidth(DtTrack::Heart, 30);
    tableView->setColumnHidden(DtTrack::Id, true);
    tableView->setColumnHidden(DtTrack::Location, true);
    tableView->setColumnHidden(DtTrack::Lyrics, true);
    tableView->setColumnHidden(DtTrack::Recovery, true);
    tableView->setColumnHidden(DtTrack::Score, true);
    connect(tableView, SIGNAL(clicked(QModelIndex)), this,
            SLOT(on_tableView_clicked(QModelIndex)));
}

WTrack::~WTrack()
{
}

void WTrack::setList(QList<AbstractData *> &lTrack)
{
    model.setList((QList<DtTrack *> &)lTrack);
}

QString WTrack::getPath()
{
    return selection;
}

void WTrack::on_tableView_clicked(const QModelIndex &index)
{
    if(!index.isValid())
        return;
    if(index.column() == DtTrack::Name)
    {
        selection = model.getList()[index.row()]->getName();
//        emit playTrack((QList<AbstractData *> &)model.getList()
//                       [index.row()]);
    }
    else
    {
        selection = "";
        switch (index.column())
        {
        case DtTrack::Play:
//            emit playTrack(model.getList()[index.row()]->getTracks());
            break;
        case DtTrack::Add:
//            emit addTrack(model.getList()[index.row()]->getTracks());
            break;
        case DtTrack::Heart:
            break;
        default:
            return;
            break;
        }
        model.getList()[index.row()]->clicked(index.column());
    }
}
